package com.etool.action.curd;


import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;


import com.etool.modules.curd.model.Column;
import com.etool.modules.curd.service.CurdService;
import com.etool.modules.curd.util.CurdConfigUtil;
import com.opensymphony.xwork2.ActionSupport;

public class IndexAction extends ActionSupport{
	
	//表名
	private String target="auth_menu";
	

	
	private CurdService curdService;
	
	private List<Column> columns;
	
	
	//是否分页
	private String pagination="true";
	//页大小数组
	private String pageList="[20,30,40,50]";
	
	

	@Action("index")
	public String index()
	{	
		//获取配置
		List<Map<String, Object>> curdConfig= curdService.read("curd_config", Collections.singletonMap("tableName",(Object)target));
		if(curdConfig!=null && curdConfig.size()==1)
		{
			pagination=(String)curdConfig.get(0).get("pagination");
			
			if(curdConfig.get(0).get("pageList")!=null && !StringUtils.isEmpty((String)curdConfig.get(0).get("pageList")))
			{
				pageList=(String)curdConfig.get(0).get("pageList");
			}
		}
		//获取配置
		
		
		CurdConfigUtil.setSecondJdbc(curdService, target);
		
		columns=curdService.desc(target);
		
		CurdConfigUtil.disableSecondJdbc(curdService);
		
		
		return SUCCESS;
	}
	
	
	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
	}
	
	public CurdService getCurdService() {
		return curdService;
	}

	public void setCurdService(CurdService curdService) {
		this.curdService = curdService;
	}

	public List<Column> getColumns() {
		return columns;
	}

	public void setColumns(List<Column> columns) {
		this.columns = columns;
	}


	public String getPagination() {
		return pagination;
	}


	public void setPagination(String pagination) {
		this.pagination = pagination;
	}


	public String getPageList() {
		return pageList;
	}


	public void setPageList(String pageList) {
		this.pageList = pageList;
	}



}
